<?php

class timeattendance {

	//variables
	public $id;
	public $date;
	public $start_time;
	public $end_time;
	public $break_start;
	public $break_end;
	public $day;
	public $approval_status;
	public $work_start_time;
	public $remarks;
	public $tempArray;
	
	
	//constuctor
	public function __construct($data) {
		
		if(is_numeric($data)) {
			$this->id = $data;
			$this->date = "";
			$this->start_time = NULL;
			$this->end_time = NULL;
			$this->break_start = NULL;
			$this->break_end = NULL;
			$this->day = "NORMAL";
			$this->approval_status = "0";
			$ths->work_start_time = "0000";
			$this->tempArray = array();
			$this->remarks = NULL;
		}
		else if (is_array($data)){
			
			$this->id = $data['id'];
			$this->date = $data['date'];
			$this->start_time = $data['start_time'];
			$this->end_time = $data['end_time'];
			$this->break_start = $data['break_start'];
			$this->break_end = $data['break_end'];
			$this->day = $data['day'];
			$this->approval_status = $data['approval_status'];
			$this->work_start_time = $data['work_start_time'];
			$this->remarks = $data['remarks'];
		}

	}

	//function
	
	public function setId($id) {
		$this->id = id;
	}
	
	public function getId() {
		return $this->id;
	}
	
	public function setDate($date) {
		$this->date = $date;
	}
	
	public function getDate() {
		return $this->date;
	}
	
	public function getStartTime() {
		return $this->start_time;
	}
	
	public function getEndTime() {
		return $this->end_time;
	}
	
	public function getBreakStart() {
		return $this->break_start;
	}
	
	public function getBreakEnd() {
		return $this->break_end;
	}
	
	public function getDay() {
		return $this->day;
	}
	
	public function setDay($day) {
		$this->day = $day;
	}
	
	public function getApprovalStatus() {
		return $this->approval_status;
	}
	
	public function setApprovalStatus($approval_status) {
		$this->approval_status = $approval_status;
	}
	
	public function getWorkStartTime() {
		return $this->work_start_time;
	}
	
	public function setWorkStartTime($work_start_time) {
		$this->work_start_time = $work_start_time;
	}

	
	public function insertTiming($timing) {
		$this->tempArray[] = $timing;
	}
	
	public function compute() {
		
		sort($this->tempArray, SORT_ASC);
		
		if(count($this->tempArray) <= 2) {
			$this->start_time = $this->tempArray[0];
			$this->end_time = $this->tempArray[1];
		}
		else {
			$this->start_time = $this->tempArray[0];
			$this->end_time = $this->tempArray[count($this->tempArray)-1];
			$this->break_start = $this->tempArray[1];
			$this->break_end = $this->tempArray[2];
		}
		
		if($this->tempArray[0] < "0200") {
				$this->start_time = $this->tempArray[1];
				$this->end_time = $this->tempArray[0];
				$this->break_start = $this->tempArray[2];
				$this->break_end = $this->tempArray[count($this->tempArray)-1];
		}
		
		if($this->start_time < "1100")
			$this->work_start_time =  "1000";
		else if ($this->start_time < "1300" )
			$this->work_start_time =  "1200";
		else if ($this->start_time < "1600")
			$this->work_start_time =   "1500";
		else if ($this->start_time < "1800")
			$this->work_start_time =   "1700";
	}
	
	
	//for testing purpose method
	public function getCount() {
		return count($this->tempArray);
	}
	
	public function setRemarks($remarks) {
		$this->remarks = $remarks;
	}
	
	public function getRemarks() {
		return $this->remarks;
	}
	
	//for testing purpose method
	public function printTempArray() {
		echo "COUNT : ".count($this->tempArray)." ";
		echo $this->tempArray[0].",";
		echo $this->tempArray[1].",";
		echo $this->tempArray[2].",";
		echo $this->tempArray[3];
		echo "<br>";
	}

	public function __toString() {
		return "Time Attendance : Id[".$this->id."], Date[".date("Y/m/d", $this->date)."], Start Time [".$this->start_time."], End Time [".$this->end_time."], Break Start [".$this->break_start."], Break End [".$this->break_end."], Work Start [".$this->work_start_time."], Remarks [".$this->remarks."]";
	}



}

?>